package p270jp.pxv.android.activity;

import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.p024v4.media.C0261e;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.DialogFragment;
import com.google.android.material.navigation.NavigationView;
import java.io.Serializable;
import java.util.Objects;
import p014ae.AdActivity;
import p014ae.C0135p4;
import p014ae.C0199z4;
import p014ae.View$OnClickListenerC0046a;
import p014ae.View$OnClickListenerC0050b;
import p018ai.PixivSettings;
import p071cd.Functions;
import p090d0.C2518n;
import p134ei.AnalyticsAction;
import p134ei.AnalyticsScreenName;
import p165fo.Subscribe;
import p210hh.PixivAccountManager;
import p232id.ObservableFlatMapSingle;
import p270jp.pxv.android.R;
import p270jp.pxv.android.commonObjects.model.WorkType;
import p270jp.pxv.android.event.BackToHomeEvent;
import p270jp.pxv.android.event.FirstLikedEvent;
import p270jp.pxv.android.event.ShareWorkEvent;
import p270jp.pxv.android.event.ShowCollectionDialogEvent;
import p270jp.pxv.android.event.ShowFollowDialogEvent;
import p270jp.pxv.android.event.ShowStartUpScreenEvent;
import p270jp.pxv.android.legacy.analytics.firebase.model.ComponentVia;
import p270jp.pxv.android.legacy.constant.ContentType;
import p270jp.pxv.android.legacy.event.ShowNovelDetailDialogEvent;
import p270jp.pxv.android.legacy.event.ShowNovelTextEvent;
import p270jp.pxv.android.legacy.model.PixivNovel;
import p270jp.pxv.android.legacy.model.PixivUser;
import p270jp.pxv.android.legacy.model.PixivWork;
import p270jp.pxv.android.model.BrowsingHistoryDaoManager;
import p274k2.ContextCompat;
import p307l9.EdgeTreatment;
import p318lk.PixivNotificationsHasUnreadStateService;
import p325m0.MutabilityOwnership;
import p347mm.AccountUtils;
import p452qn.C5859m;
import p517td.BehaviorSubject;
import p545uf.StringUtils;
import p547uh.CollectionDialogFragment;
import p547uh.ConfirmHomeRecommendedDialogFragment;
import p547uh.FollowDialogFragment;
import p547uh.NovelDetailDialogFragment;
import p603wm.AbstractC6949c;
import p625xi.LegacyNavigation;
import p639y6.C7296l;
import p645yc.AndroidSchedulers;
import p665z6.C7461p;
import p671zc.CompositeDisposable;
import p674zf.UploadedContent;
import p677zi.PixivImageLoader;

/* compiled from: NavigationActivity.java */
/* renamed from: jp.pxv.android.activity.b */
/* loaded from: classes2.dex */
public abstract class AbstractActivityC4151b extends AdActivity {

    /* renamed from: R */
    public static final /* synthetic */ int f18772R;

    /* renamed from: J */
    public DrawerLayout f18773J;

    /* renamed from: K */
    public NavigationView f18774K;

    /* renamed from: N */
    public AbstractC6949c<LegacyNavigation> f18777N;

    /* renamed from: L */
    public boolean f18775L = true;

    /* renamed from: M */
    public CompositeDisposable f18776M = new CompositeDisposable();

    /* renamed from: O */
    public final PixivNotificationsHasUnreadStateService f18778O = (PixivNotificationsHasUnreadStateService) C2518n.m7641d(PixivNotificationsHasUnreadStateService.class);

    /* renamed from: P */
    public final PixivImageLoader f18779P = (PixivImageLoader) C2518n.m7641d(PixivImageLoader.class);

    /* renamed from: Q */
    public Boolean f18780Q = Boolean.FALSE;

    public AbstractActivityC4151b() {
    }

    /* renamed from: a1 */
    public final int m4676a1() {
        TypedValue typedValue = new TypedValue();
        if (getTheme().resolveAttribute(R.attr.colorCharcoalIcon3, typedValue, true)) {
            return typedValue.data;
        }
        throw new IllegalStateException("Charcoal Theme, もしくは Charcoal Bridge Theme を利用してください");
    }

    /* renamed from: b1 */
    public void mo4578b1(boolean z) {
    }

    /* renamed from: c1 */
    public final void m4675c1(boolean z) {
        Drawable drawable;
        LayerDrawable layerDrawable;
        mo4578b1(z);
        Boolean valueOf = Boolean.valueOf(z);
        NavigationView navigationView = this.f18774K;
        if (navigationView != null) {
            this.f18780Q = valueOf;
            MenuItem findItem = navigationView.getMenu().findItem(R.id.drawer_menu_notification);
            if (valueOf.booleanValue()) {
                Object obj = ContextCompat.f19963a;
                drawable = ContextCompat.C4472c.m4259b(this, R.drawable.ic_nav_notification_eclipse);
                if (drawable != null) {
                    LayerDrawable layerDrawable2 = new LayerDrawable(new Drawable[]{drawable, ContextCompat.C4472c.m4259b(this, R.drawable.ic_unread_dot)});
                    layerDrawable2.setLayerGravity(1, 53);
                    int dimensionPixelSize = getResources().getDimensionPixelSize(R.dimen.unread_dot_size);
                    layerDrawable2.setLayerSize(1, dimensionPixelSize, dimensionPixelSize);
                    layerDrawable = layerDrawable2;
                } else {
                    return;
                }
            } else {
                Object obj2 = ContextCompat.f19963a;
                drawable = ContextCompat.C4472c.m4259b(this, R.drawable.ic_nav_notification);
                if (drawable != null) {
                    layerDrawable = drawable;
                } else {
                    return;
                }
            }
            drawable.setColorFilter(m4676a1(), PorterDuff.Mode.SRC_IN);
            findItem.setIcon(layerDrawable);
        }
    }

    /* renamed from: d1 */
    public final void m4674d1() {
        NavigationView navigationView = this.f18774K;
        if (navigationView != null && this.f18775L) {
            this.f18775L = false;
            View childAt = navigationView.f9631g.f13385b.getChildAt(0);
            if (childAt == null) {
                childAt = this.f18774K.m8491c(R.layout.drawer_header);
            }
            PixivAccountManager e = PixivAccountManager.m5511e();
            this.f18779P.m60f(this, e.f16502h, (ImageView) childAt.findViewById(R.id.user_profile_image_view));
            ((TextView) childAt.findViewById(R.id.user_name_text_view)).setText(e.f16498d);
            childAt.setOnClickListener(new View$OnClickListenerC0050b(this, 3));
            TextView textView = (TextView) childAt.findViewById(R.id.premium_text_view);
            textView.setText(getString(e.f16503i ? R.string.premium : R.string.premium_about));
            textView.setOnClickListener(new View$OnClickListenerC0046a(this, 3));
            this.f18774K.getMenu().findItem(R.id.drawer_menu_notification).setVisible(true);
            if (!PixivAccountManager.m5511e().f16503i) {
                MenuItem findItem = this.f18774K.getMenu().findItem(R.id.drawer_menu_browsing_history);
                String str = getString(R.string.browsing_history) + " [P]";
                MutabilityOwnership.m3745m(str, "rawText");
                Object obj = ContextCompat.f19963a;
                Drawable b = ContextCompat.C4472c.m4259b(this, R.drawable.ic_profile_premium);
                EdgeTreatment.m3909i(b);
                MutabilityOwnership.m3747j(b);
                b.setBounds(0, 0, b.getIntrinsicWidth(), b.getIntrinsicHeight());
                StringUtils bVar = new StringUtils(b);
                SpannableString spannableString = new SpannableString(str);
                int J = C5859m.m2737J(str, "[P]", 0, false, 6);
                int i = J + 3;
                if (J >= 0) {
                    spannableString.setSpan(bVar, J, i, 17);
                }
                findItem.setTitle(spannableString);
            }
            SpannableString spannableString2 = new SpannableString(getString(R.string.connection));
            TypedValue typedValue = new TypedValue();
            if (getTheme().resolveAttribute(R.attr.colorCharcoalText1, typedValue, true)) {
                int i2 = typedValue.data;
                spannableString2.setSpan(new ForegroundColorSpan(i2), 0, spannableString2.length(), 0);
                this.f18774K.getMenu().findItem(R.id.drawer_menu_connections).setTitle(spannableString2);
                if (this.f18774K.getMenu().findItem(R.id.drawer_menu_connections).isVisible()) {
                    int[] iArr = {R.id.drawer_menu_following, R.id.drawer_menu_follower, R.id.drawer_menu_mypixiv};
                    int[] iArr2 = {R.string.connection_following, R.string.connection_follower, R.string.connection_mypixiv};
                    for (int i3 = 0; i3 < 3; i3++) {
                        MenuItem findItem2 = this.f18774K.getMenu().findItem(iArr[i3]);
                        StringBuilder c = C0261e.m12042c("\u3000");
                        c.append(getString(iArr2[i3]));
                        findItem2.setTitle(c.toString());
                    }
                }
                SpannableString spannableString3 = new SpannableString(getString(R.string.others));
                spannableString3.setSpan(new ForegroundColorSpan(i2), 0, spannableString3.length(), 0);
                this.f18774K.getMenu().findItem(R.id.drawer_menu_others).setTitle(spannableString3);
                this.f18774K.setNavigationItemSelectedListener(new C7296l(this, 6));
                this.f18774K.setItemIconTintList(null);
                Menu menu = this.f18774K.getMenu();
                for (int i4 = 0; i4 < menu.size(); i4++) {
                    MenuItem item = menu.getItem(i4);
                    Drawable icon = item.getIcon();
                    if (icon != null) {
                        icon.setColorFilter(m4676a1(), PorterDuff.Mode.SRC_IN);
                    }
                    if (item.hasSubMenu()) {
                        SubMenu subMenu = item.getSubMenu();
                        for (int i5 = 0; i5 < subMenu.size(); i5++) {
                            Drawable icon2 = subMenu.getItem(i5).getIcon();
                            if (icon2 != null) {
                                icon2.setColorFilter(m4676a1(), PorterDuff.Mode.SRC_IN);
                            }
                        }
                    }
                }
                return;
            }
            throw new IllegalStateException("Charcoal Theme, もしくは Charcoal Bridge Theme を利用してください");
        }
    }

    @Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, android.app.Activity
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        PixivSettings bVar = (PixivSettings) C2518n.m7641d(PixivSettings.class);
        if (i2 == -1 && i == 105) {
            PixivNovel pixivNovel = (PixivNovel) intent.getSerializableExtra("NOVEL");
            if (pixivNovel != null) {
                Intent intent2 = new Intent(this, NovelTextActivity.class);
                intent2.putExtra("NOVEL_ID", pixivNovel.f19079id);
                intent2.putExtra("NOVEL", pixivNovel);
                intent2.putExtra("VIA", (Parcelable) null);
                intent2.putExtra("PREVIOUS_SCREEN", (Serializable) null);
                startActivityForResult(intent2, 105);
            }
        } else if (i2 == -1 && i == 401) {
            if (intent.getSerializableExtra("CONTENT") == UploadedContent.ILLUST) {
                bVar.m12121g(WorkType.ILLUST);
                startActivity(new Intent(this, MyWorkActivity.class));
            } else if (intent.getSerializableExtra("CONTENT") == UploadedContent.MANGA) {
                bVar.m12121g(WorkType.MANGA);
                startActivity(new Intent(this, MyWorkActivity.class));
            }
        } else if (i2 == -1 && i == 402) {
            bVar.m12121g(WorkType.NOVEL);
            startActivity(new Intent(this, MyWorkActivity.class));
        } else if (i == 109 && i2 == -1 && intent.getBooleanExtra("result_key_should_show_mail_authorization", false)) {
            AccountUtils.m3550d(this, this.f18776M);
        }
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public void onBackPressed() {
        DrawerLayout drawerLayout = this.f18773J;
        if (drawerLayout == null || !drawerLayout.m11347n(8388611)) {
            this.f940i.m12030b();
        } else {
            this.f18773J.m11357d(false);
        }
    }

    @Override // p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.f18777N = C2518n.m7638h(LegacyNavigation.class);
    }

    @Subscribe
    public void onEvent(ShowNovelTextEvent showNovelTextEvent) {
        PixivNovel novel = showNovelTextEvent.getNovel();
        ComponentVia via = showNovelTextEvent.getVia();
        AnalyticsScreenName previousScreen = showNovelTextEvent.getPreviousScreen();
        MutabilityOwnership.m3745m(novel, "novel");
        Intent intent = new Intent(this, NovelTextActivity.class);
        intent.putExtra("NOVEL_ID", novel.f19079id);
        intent.putExtra("NOVEL", novel);
        intent.putExtra("VIA", via);
        intent.putExtra("PREVIOUS_SCREEN", previousScreen);
        startActivityForResult(intent, 105);
        ((BrowsingHistoryDaoManager) C2518n.m7641d(BrowsingHistoryDaoManager.class)).insertWithPixivWork(showNovelTextEvent.getNovel());
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != 16908332) {
            return super.onOptionsItemSelected(menuItem);
        }
        onBackPressed();
        return true;
    }

    @Override // p014ae.AdActivity, p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onPause() {
        super.onPause();
        this.f18775L = true;
        this.f18776M.m80f();
    }

    @Override // p014ae.AdActivity, p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onResume() {
        super.onResume();
        m4674d1();
        PixivNotificationsHasUnreadStateService eVar = this.f18778O;
        BehaviorSubject<Boolean> aVar = eVar.f22596b;
        C7461p pVar = new C7461p(eVar, 29);
        Objects.requireNonNull(aVar);
        this.f18776M.mo82c(new ObservableFlatMapSingle(aVar, pVar, false).m994f().m986o(AndroidSchedulers.m334a()).m984q(new C0135p4(this, 2), C0199z4.f694c, Functions.f5386c, Functions.f5387d));
        m4675c1(false);
    }

    @Override // p014ae.AdActivity, p116e.ActivityC2727f, androidx.activity.ComponentActivity, android.app.Activity
    public void setContentView(int i) {
        super.setContentView(i);
        this.f18773J = (DrawerLayout) findViewById(R.id.drawer_layout);
        this.f18774K = (NavigationView) findViewById(R.id.nav_view);
        m4674d1();
    }

    public AbstractActivityC4151b(int i) {
        super(i);
    }

    @Subscribe
    public void onEvent(ShowNovelDetailDialogEvent showNovelDetailDialogEvent) {
        if (m11131K0().m11279F("novel_detail_dialog") != null) {
            ((DialogFragment) m11131K0().m11279F("novel_detail_dialog")).dismiss();
        }
        if (!isFinishing() && !isDestroyed()) {
            PixivNovel novel = showNovelDetailDialogEvent.getNovel();
            ComponentVia via = showNovelDetailDialogEvent.getVia();
            AnalyticsScreenName previousScreen = showNovelDetailDialogEvent.getPreviousScreen();
            Long previousScreenId = showNovelDetailDialogEvent.getPreviousScreenId();
            NovelDetailDialogFragment l6Var = new NovelDetailDialogFragment();
            Bundle bundle = new Bundle();
            bundle.putSerializable("NOVEL", novel);
            bundle.putParcelable("VIA", via);
            bundle.putSerializable("PREVIOUS_SCREEN", previousScreen);
            if (previousScreenId != null) {
                bundle.putLong("PREVIOUS_SCREEN_ID", previousScreenId.longValue());
            }
            l6Var.setArguments(bundle);
            l6Var.show(m11131K0(), "novel_detail_dialog");
        }
    }

    @Subscribe
    public void onEvent(FirstLikedEvent firstLikedEvent) {
        this.f18757A.m6528b(15, AnalyticsAction.NEW_USER_END_FIRST_LIKE);
        WorkType workType = firstLikedEvent.getWorkType();
        ConfirmHomeRecommendedDialogFragment c0Var = new ConfirmHomeRecommendedDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("WORK_TYPE", workType);
        c0Var.setArguments(bundle);
        c0Var.show(m11131K0(), "confirm_home_recommended_dialog");
    }

    @Subscribe
    public void onEvent(BackToHomeEvent backToHomeEvent) {
        WorkType workType = backToHomeEvent.getWorkType();
        MutabilityOwnership.m3745m(workType, "workType");
        Intent intent = new Intent(this, HomeActivity.class);
        intent.putExtra("WORK_TYPE", workType);
        intent.setFlags(268468224);
        startActivity(intent);
    }

    @Subscribe
    public void onEvent(ShowCollectionDialogEvent showCollectionDialogEvent) {
        if (showCollectionDialogEvent.getWork() != null) {
            ContentType contentType = showCollectionDialogEvent.getContentType();
            PixivWork work = showCollectionDialogEvent.getWork();
            AnalyticsScreenName screenName = showCollectionDialogEvent.getScreenName();
            int i = CollectionDialogFragment.f28124o;
            EdgeTreatment.m3909i(contentType);
            EdgeTreatment.m3909i(work);
            CollectionDialogFragment wVar = new CollectionDialogFragment();
            Bundle bundle = new Bundle();
            bundle.putParcelable("CONTENT_TYPE", contentType);
            bundle.putSerializable("WORK", work);
            bundle.putSerializable("SCREEN_NAME", screenName);
            wVar.setArguments(bundle);
            wVar.show(m11131K0(), "collection_dialog");
        }
    }

    @Subscribe
    public void onEvent(ShowFollowDialogEvent showFollowDialogEvent) {
        PixivUser targetUser = showFollowDialogEvent.getTargetUser();
        MutabilityOwnership.m3745m(targetUser, "targetUser");
        Bundle bundle = new Bundle();
        bundle.putSerializable("TARGET_USER", targetUser);
        FollowDialogFragment i0Var = new FollowDialogFragment();
        i0Var.setArguments(bundle);
        i0Var.show(m11131K0(), "follow_dialog");
    }

    @Subscribe
    public void onEvent(ShareWorkEvent shareWorkEvent) {
        String shareBody = shareWorkEvent.getShareBody();
        MutabilityOwnership.m3745m(shareBody, "shareText");
        Intent intent = new Intent("android.intent.action.SEND");
        intent.setType("text/plain");
        intent.putExtra("android.intent.extra.TEXT", shareBody);
        startActivity(Intent.createChooser(intent, null));
    }

    @Subscribe
    public void onEvent(ShowStartUpScreenEvent showStartUpScreenEvent) {
        int ordinal = showStartUpScreenEvent.getStartUpScreen().ordinal();
        if (ordinal == 0) {
            m4677U0(new Intent(this, HomeActivity.class));
            overridePendingTransition(0, 0);
            finish();
        } else if (ordinal == 1) {
            m4677U0(new Intent(this, NewWorksActivity.class));
            overridePendingTransition(0, 0);
            finish();
        } else if (ordinal == 2) {
            m4677U0(new Intent(this, SearchTopActivity.class));
            overridePendingTransition(0, 0);
            finish();
        }
    }
}
